/*
 * @FilePath: /wkw/vite.prod.config.ts
 * 介绍:生产环境配置项
 */

import { defineConfig, loadEnv, ConfigEnv } from "vite";
import path from "path";

export default (config: ConfigEnv) => {
  const env = loadEnv(config.mode, process.cwd(), "VITE_");

  return defineConfig({
    build: {
      minify: "terser",
      rollupOptions: {
        output: {
          chunkFileNames: "static/js/[name]-[hash].js",
          entryFileNames: "static/js/[name]-[hash].js",
          assetFileNames: "static/[ext]/[name]-[hash].[ext]",
        },
        manualChunks(id) {
          if (id.includes("node_modules")) {
            return "vendor";
          }
        },
      },
      outDir: path.join(__dirname, "dist/build"),
      terserOptions: {
        compress: {
          drop_console: true, // 生产环境移除console
          drop_debugger: true, // 生产环境移除debugger
        },
      },
    },
  });
};
